package com.onion.auth.handler;

import com.onion.auth.context.AclContext;
import com.onion.auth.support.AuthManager;

/**
 * URL访问处理器
 */
public class UrlAuthHandler implements AclHandler {

    private TokenUserHandler tokenUserHandler = new TokenUserHandler();

    @Override
    public boolean handle(AclContext context) {
        String requestResource = context.getRequestResource();
        if(AuthManager.allowPermission(context.getRequestToken(), context.getRequestResource())){
            //预处理
            tokenUserHandler.preHandle(context);
            //注册PostHandler
            context.pushPostHandler(tokenUserHandler);
            return true;
        }else{
            return false;
        }
    }

}